doctype html
html
    head
        link(rel="icon" href="/Favicon.ico" type="image/x-icon")
        link(rel='stylesheet' type='text/css' href='stylesheets/viewtables.css')
        script(type="text/javascript" src="javascripts/jQueryMytable.js")
        script(type="text/javascript" src="javascripts/table2excel.js")
        script(type="text/javascript" src="javascripts/localstorage/localstorage.js")
        title #{TitleBar}
        script(type='text/javascript' src='javascripts/jquery.wheelmenu.js')
        link(rel='stylesheet' type='text/css' href='stylesheets/default.css')
        link(rel='stylesheet' type='text/css' href='stylesheets/style.css')
        link(rel='stylesheet' type='text/css' href='stylesheets/elusive-webfont.css')
        body
            //右击选项卡功能
            #menutab
                ul
                    li
                        a(href='javascript:void(0)' onclick="ViDaSou()") 查看数据来源
            //弹出菜单显示详细数据来源框begin
            #hidebg
                p.lrcenter(onclick='hide();' style="font-size:20px;color:red;") 点击关闭
                #strtWrap.strt-wrap
                    .strt-block
                        .strt-block
                            .strt-part
                                span.strt-name.Department 金石物流
                                .line-v
                                    span
                                .strt-block.part-contenct

            #hidebox
            // 右下角功能按钮
            .box(style="position: fixed;right: 17px;bottom: 17px;z-index: 100;")
                a.wheel-button.nw(href='#wheel4')
                    i.customicon-plus
                ul#wheel4.wheel(data-angle='NW')
                    li.item
                        a(href='#' title="分析")
                            i.customicon-search
                    li.item
                        a(href='#' title="全屏")
                            i.customicon-screen(onclick="fullScreen(document.documentElement)")
                    li.item(onclick="reserveddecimal()")
                        a(href='#' title="切换小数位数")
                            i(style="font-family:icomoon;") 
            table(id="table2",style="border-bottom-color: black; border-top-color: black; width: 3000px; color: #000000; border-right-color: black; font-size: medium; border-left-color: black" border="1" cellspacing="0" cellpadding="0")
                thead
                    tr
                        th(colspan="37",style="height:60px;text-align:left;font-size:20px;font-weight:700;") #{TitleBar}
                    tr
                        th(colspan="37",style="text-align:left;") 金额单位：万元
                    tr
                        //th(rowspan="4") id
                        th(rowspan="4") 行号
                        th(rowspan="4") 科目
                        th.bgkeee(colspan="6") 公司#{Year - 1}年度
                        th.bgkc(colspan="7") 公司#{Year}年度
                        th.bgkcd(colspan="4") #{Month<=1?Year-1:Year}年#{Month<=1?12:Month-1}月份
                        th.bgkcd(colspan="13") #{Year}年#{Month}月份
                        th.bgkac(colspan="2") #{Month == 12 ? Number(Year) + 1 : Year}年#{Month == 12 ? 1 : Month + 1}月份
                        th(rowspan="4") 年份
                        th(rowspan="4") 月份
                        th(rowspan="4") 修改日期
                    tr
                        th.bgkeee(colspan="4",rowspan="2") 实际( #{Month} 月份)
                        th.bgkeee(colspan="2",rowspan="2") 实际(1-#{Month}月份累计)
                        th.bgkc(colspan="2",rowspan="2") 计划(年度预算)
                        th.bgkc(colspan="5",rowspan="2") 实际(1-#{Month}月份累计)
                        th.bgkcd(colspan="4",rowspan="2") 实际
                        th.bgkcd(colspan="2",rowspan="2") 计划
                        th.bgkcd(colspan="5",rowspan="2") 实际
                        th.bgkcd(colspan="6") 差异
                        th.bgkac(colspan="2",rowspan="2") 计划
                    tr
                        th.bgkcd(colspan="2") 环比
                        th.bgkcd(colspan="2") 同比
                        th.bgkcd(colspan="2") 计划比
                    tr
                        th.bgkeee
                            input(type="text" value="抓取")
                        th.bgkeee
                            input(type="text" value="调整")
                        th.bgkeee
                            input(type="text" value="金额")
                        th.bgkeee
                            input(type="text" value="比率")
                        th.bgkeee
                            input(type="text" value="金额")
                        th.bgkeee
                            input(type="text" value="比率")
                        th.bgkc
                            input(type="text" value="金额")
                        th.bgkc
                            input(type="text" value="比率")
                        th.bgkc
                            input(type="text" value="金额")
                        th.bgkc
                            input(type="text" value="比率")
                        th.bgkc
                            input(type="text" value="完成率")
                        th.bgkc
                            input(type="text" value="累比增减额")
                        th.bgkc
                            input(type="text" value="累比增减率")
                        th.bgkcd
                            input(type="text" value="抓取")
                        th.bgkcd
                            input(type="text" value="调整")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="比率")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="比率")
                        th.bgkcd
                            input(type="text" value="抓取")
                        th.bgkcd
                            input(type="text" value="调整")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="比率")
                        th.bgkcd
                            input(type="text" value="完成率")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="增降幅%")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="增降幅%")
                        th.bgkcd
                            input(type="text" value="金额")
                        th.bgkcd
                            input(type="text" value="增降幅%")
                        th.bgkac
                            input(type="text" value="金额")
                        th.bgkac
                            input(type="text" value="比率")

                    each val, index in data_field
                        each i, index1 in val
                            if i != 'id'
                                th(style="position: absolute; top: -999em;")= i
                tbody
                    each val, index in data_result
                        case index
                            when 14
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 18
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 24
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 28
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 30
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 53
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 54
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 55
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 75
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 121
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 122
                                tr.bgk
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 123
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 124
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 125
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 126
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 127
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 128
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 129
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 130
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 131
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 132
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 133
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 134
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            when 135
                                tr.bgkorang
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
                            default
                                tr
                                    each i, index1 in val
                                        if index1 != 'id'
                                            td= i
            script(src='javascripts/jquery.ui.draggable.min.js', type='text/javascript')
            script(type="text/javascript" src="javascripts/localstorage/localstorage.js")
            script.
                window.onload = function () {
                    storage.remove("decimaldigit");//刷新浏览器清除小数点的存储
                }
                // 单击行列变色begin
                $("#table2 tbody td").click(function () {
                    var index = $(this).parents("tr").find("td").index($(this)) + 1;
                    var indextr = $('#table2 tr').index($(this).parent("tr"));
                    if (indextr === -1) {
                        indextr = $('#table2_tableColumnClone tr').index($(this).parent("tr"))
                    }
                    $(this).parent().parent().children("tr").removeClass("borBlue");
                    $("#table2_tableLayout tbody tr").removeClass("borBlue");
                    $("#table2_tableLayout tbody td").removeClass("borBlue");
                    $("#table2_tableLayout tbody td").removeClass("borRed");
                    $(this).addClass("borRed");
                    // $(this).parent().addClass("borBlue");
                    $('#table2_tableLayout #table2 tr').eq(indextr).addClass("borBlue");
                    $('#table2_tableLayout #table2_tableColumnClone tr').eq(indextr).addClass("borBlue");
                    $("tr td:nth-child(" + index + ")").addClass("borBlue");
                });
                // 单击行列变色end
                function reserveddecimal() {//调整页面小数的显示位数
                    var decimaldigit=storage.get("decimaldigit");
                    if(!decimaldigit){
                        decimaldigit=6;
                    }else if(decimaldigit["decimaldigit"]==6){
                        decimaldigit=2;
                    }else{
                        decimaldigit = 6;
                    }
                    storage.set("decimaldigit",{decimaldigit:decimaldigit});
                    var tableName = decodeURIComponent(getUrlParms("tableName").split(",")[0]);//获取地址栏的参数并且编码转译
                    var data1 = {
                        decimaldigit:decimaldigit,//小数位数
                        tableName: tableName//要修改的值是哪个部门
                    };
                    $.ajax({
                        type: 'POST',
                        url: "/editortable/reserveddecimal",
                        data: data1,
                        success: function (res) {
                            if (res.Modification) {
                                var result = res.result, k;
                                for (var i in result) {
                                    k = -2;
                                    for (var j in result[i]) {
                                        k++;
                                        if (j === "id") continue;
                                        $("#table2 tbody tr").eq(i).find("td").eq(k).text(result[i][j]);
                                    }
                                }
                                return;
                            }
                            alert("数据修改失败,请输入正确的格式");
                            document.getElementsByClassName("tdValuei")[0].focus();
                        }
                    });
                }
                //点击按钮查看begin
                function ViDaSou() {
                    var dataFiled = storage.get("CellInfo");
                    console.log(dataFiled);
                    var hideobj = document.getElementById("hidebg");
                    var strtwrap = document.getElementsByClassName("strt-wrap");
                    hidebg.style.display = "block";  //显示隐藏层
                    hidebg.style.height = document.body.clientHeight + "px";  //设置隐藏层的高度为当前页面高度
                    strtwrap[0].style.width = "100%";
                    $.ajax({
                        type: "POST",
                        async: false,//同步
                        url: "/editortable/ViDaSou",
                        data: dataFiled,
                        success: function (data) {
                            if (data.BasicData.indexOf("最底层") != -1) {
                                console.log(data.BasicData)
                                document.getElementById("hidebox").style.display = "block";  //显示弹出层
                                $(".strt-wrap").css({
                                    "display": "none"
                                })
                                $("#hidebox").children().remove();
                                $("#hidebox").append("<div>" + data.BasicData + "</div>");
                            } else {
                                $(".strt-wrap").css({
                                    "display": "block",
                                    "position": "absolute",
                                    "top": "25%"
                                })
                                $(".strt-block:first").css({
                                    "display": "block",
                                    "position": "relative",
                                    "left": "50%",
                                    "transform": "translateX(-50%)",
                                })
                                $(".Department").text("");
                                $(".Department").append(dataFiled.tableName);
                                $(".part-contenct").children().remove();
                                for (var i = 0; i < data.BasicData.length; i++) {
                                    if (i === 0) {

                                        var strtpart = '<div class="strt-part">\n' +
                                            '<span class="line-h line-h-r"></span>\n' +
                                            '<div class="line-v"><span></span></div>\n' +
                                            '<span class="strt-name">\n' +
                                            '<p>' + data.BasicData[i].table_name.split("_")[0] + '</p>\n' +
                                            '<p>' + data.BasicData[i]["valva"] + '</p>\n' +
                                            '</span>\n' +
                                            '</div>';
                                    } else if (i === data.BasicData.length - 1) {
                                        strtpart = '<div class="strt-part">\n' +
                                            '<span class="line-h line-h-l"></span>\n' +
                                            '<div class="line-v"><span></span></div>\n' +
                                            '<span class="strt-name">\n' +
                                            '<p>' + data.BasicData[i].table_name.split("_")[0] + '</p>\n' +
                                            '<p>' + data.BasicData[i]["valva"] + '</p>\n' +
                                            '</span>\n' +
                                            '</div>';
                                    } else {
                                        strtpart = '<div class="strt-part">\n' +
                                            '<span class="line-h line-h-c"></span>\n' +
                                            '<div class="line-v"><span></span></div>\n' +
                                            '<span class="strt-name">\n' +
                                            '<p>' + data.BasicData[i].table_name.split("_")[0] + '</p>\n' +
                                            '<p>' + data.BasicData[i]["valva"] + '</p>\n' +
                                            '</span>\n' +
                                            '</div>';
                                    }
                                    $(".part-contenct").append(strtpart);
                                }
                                console.log(data.BasicData)
                            }
                        }
                    })
                }


                // 点击按钮关闭begin
                function hide()  //去除隐藏层和弹出层
                {
                    document.getElementById("hidebg").style.display = "none";
                    document.getElementById("hidebox").style.display = "none";
                }
                var tableId = document.getElementById('table2');
                //右击选项卡功能begin
                var table2 = tableId;
                var tds = tableId.getElementsByTagName("td");
                for (var i = 0; i < tds.length; i++) {
                    (function (i) {
                        tds[i].oncontextmenu = function (e) {
                            var lineNumber = $(this).parent("tr").children("td").eq(0).text();
                            var Num = $(this).parents("tr").find("td").index($(this));
                            var field = $("#table2>thead>tr").eq(6).children("th").eq(Num).text();
                            var tableName = decodeURIComponent(getUrlParms("tableName").split(",")[0]);//获取地址栏的参数并且编码转译
                            var data1 = {
                                lineNumber: lineNumber,//行号
                                field: field,//字段
                                tableName: tableName//要修改的值是哪个部门
                            };
                            storage.set("CellInfo", data1)
                            if (window.event) e = window.event;
                            var mymenu = document.getElementById("menutab");
                            mymenu.style.visibility = "visible";
                            mymenu.style.left = e.clientX + 0 + "px";
                            mymenu.style.top = e.clientY + 0 + "px";
                            return false;
                        }
                    })(i)
                }
                document.onclick = function () {
                    var mymenu = document.getElementById("menutab");
                    mymenu.style.visibility = "hidden";
                }
                //右击选项卡功能end
                //下载功能begin
                // var tableId = document.getElementById('table2');
                function toexcel() {
                    var tableName = decodeURIComponent(getUrlParms("tableName").split(",")[0]);
                    $("#table2").table2excel({
                        exclude: ".noExl", //过滤位置的 css 类名
                        filename: tableName + ".xls", //文件名称
                        name: "Excel Document Name.xlsx",
                        exclude_img: true,
                        exclude_links: true,
                        exclude_inputs: true
                    });
                }

                //下载功能end
                function FixTable(TableID, FixColumnNumber, width, height) {
                    //TableID            要锁定的Table的ID
                    //FixColumnNumber    要锁定列的个数
                    //width              显示的宽度
                    //height             显示的高度
                    if ($("#" + TableID + "_tableLayout").length != 0) {
                        $("#" + TableID + "_tableLayout").before($("#" + TableID));
                        $("#" + TableID + "_tableLayout").empty();
                    }
                    else {
                        $("#" + TableID).after("<div id='" + TableID + "_tableLayout' style='overflow:hidden; width:" + width + "px;'></div>");
                    }
                    $('<div id="' + TableID + '_tableFix"></div>'
                        + '<div id="' + TableID + '_tableHead"></div>'
                        + '<div id="' + TableID + '_tableColumn"></div>'
                        + '<div id="' + TableID + '_tableData"></div>').appendTo("#" + TableID + "_tableLayout");
                    var oldtable = $("#" + TableID);
                    var tableFixClone = oldtable.clone(true);
                    tableFixClone.attr("id", TableID + "_tableFixClone");
                    $("#" + TableID + "_tableFix").append(tableFixClone);
                    var tableHeadClone = oldtable.clone(true);
                    tableHeadClone.attr("id", TableID + "_tableHeadClone");
                    $("#" + TableID + "_tableHead").append(tableHeadClone);
                    var tableColumnClone = oldtable.clone(true);
                    tableColumnClone.attr("id", TableID + "_tableColumnClone");
                    $("#" + TableID + "_tableColumn").append(tableColumnClone);
                    $("#" + TableID + "_tableData").append(oldtable);
                    $("#" + TableID + "_tableLayout table").each(function () {
                        $(this).css("margin", "0");
                    });
                    var HeadHeight = $("#" + TableID + "_tableHead thead").height();
                    HeadHeight += 2;
                    $("#" + TableID + "_tableHead").css("height", HeadHeight);
                    $("#" + TableID + "_tableFix").css("height", HeadHeight);
                    var ColumnsWidth = 0;
                    var ColumnsNumber = 0;
                    $("#" + TableID + "_tableColumn tr:last td:lt(" + FixColumnNumber + ")").each(function () {
                        ColumnsWidth += $(this).outerWidth(true);
                        ColumnsNumber++;
                    });
                    ColumnsWidth += 2;
                    if ($.browser.msie) {
                        switch ($.browser.version) {
                            case "7.0":
                                if (ColumnsNumber >= 3) ColumnsWidth--;
                                break;
                            case "8.0":
                                if (ColumnsNumber >= 2) ColumnsWidth--;
                                break;
                        }
                    }
                    $("#" + TableID + "_tableColumn").css("width", ColumnsWidth);
                    $("#" + TableID + "_tableFix").css("width", ColumnsWidth);
                    $("#" + TableID + "_tableData").scroll(function () {
                        $("#" + TableID + "_tableHead").scrollLeft($("#" + TableID + "_tableData").scrollLeft());
                        $("#" + TableID + "_tableColumn").scrollTop($("#" + TableID + "_tableData").scrollTop());
                    });
                    $("#" + TableID + "_tableFix").css({
                        "overflow": "hidden",
                        "position": "relative",
                        "z-index": "50",
                        "background-color": "white"
                    });
                    $("#" + TableID + "_tableHead").css({
                        "overflow": "hidden",
                        "width": width - 17,
                        "position": "relative",
                        "z-index": "45",
                        "background-color": "white"
                    });
                    $("#" + TableID + "_tableColumn").css({
                        "overflow": "hidden",
                        "height": height - 17,
                        "position": "relative",
                        "z-index": "40",
                        "background-color": "white"
                    });
                    $("#" + TableID + "_tableData").css({
                        "overflow": "scroll",
                        "width": width,
                        "height": height,
                        "position": "relative",
                        "z-index": "35"
                    });
                    if ($("#" + TableID + "_tableHead").width() > $("#" + TableID + "_tableFix table").width()) {
                        $("#" + TableID + "_tableHead").css("width", $("#" + TableID + "_tableFix table").width());
                        $("#" + TableID + "_tableData").css("width", $("#" + TableID + "_tableFix table").width() + 17);
                    }
                    if ($("#" + TableID + "_tableColumn").height() > $("#" + TableID + "_tableColumn table").height()) {
                        $("#" + TableID + "_tableColumn").css("height", $("#" + TableID + "_tableColumn table").height());
                        $("#" + TableID + "_tableData").css("height", $("#" + TableID + "_tableColumn table").height() + 17);
                    }
                    $("#" + TableID + "_tableFix").offset($("#" + TableID + "_tableLayout").offset());
                    $("#" + TableID + "_tableHead").offset($("#" + TableID + "_tableLayout").offset());
                    $("#" + TableID + "_tableColumn").offset($("#" + TableID + "_tableLayout").offset());
                    $("#" + TableID + "_tableData").offset($("#" + TableID + "_tableLayout").offset());
                }
                function getUrlParms(name) {//获取地址栏传递的参数
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                    var r = window.location.search.substr(1).match(reg);
                    if (r != null)
                        return unescape(r[2]);
                    return null;
                }
                //判断是否为数字
                function isRealNum(val) {
                    // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
                    if (val === "" || val == null) {
                        return false;
                    }
                    if (!isNaN(val)) {
                        return true;
                    } else {
                        return false;
                    }
                }
                var tbwidth = document.body.clientWidth;
                var tbheight = document.documentElement.clientHeight;
                FixTable("table2", 2, tbwidth, tbheight);
                $(document).ready(function () {
                    window.onresize = function () {
                        tbwidth = document.body.clientWidth;
                        tbheight = document.documentElement.clientHeight;
                        FixTable("table2", 2, tbwidth, tbheight);
                    };
                });
                // 右下角浮动导航
                $(".wheel-button").wheelmenu({
                    trigger: "click",
                    animation: "fly",
                    angle: [180, 270]
                });

                //全屏
                function fullScreen(element) {
                    var tbwidth = document.body.clientWidth;
                    var tbheight = document.documentElement.clientHeight;
                    if (document.documentElement.RequestFullScreen) {
                        document.documentElement.RequestFullScreen();
                    }
                    //兼容火狐
                    console.log(document.documentElement.mozRequestFullScreen)
                    if (document.documentElement.mozRequestFullScreen) {
                        document.documentElement.mozRequestFullScreen();
                    }
                    //兼容谷歌等可以webkitRequestFullScreen也可以webkitRequestFullscreen
                    if (document.documentElement.webkitRequestFullScreen) {
                        document.documentElement.webkitRequestFullScreen();
                    }
                    //兼容IE,只能写msRequestFullscreen
                    if (document.documentElement.msRequestFullscreen) {
                        document.documentElement.msRequestFullscreen();
                    }
                }

